import Vue from 'vue'
import Router from 'vue-router'
import index  from '@/view/index'
import attention from '@/view/attention'
import about from '@/view/about'
import writeArticle from '@/view/writeArticle'
import register from '@/view/register'
import login from '@/view/login'
import comment from '@/component/commentArticle'
import searchArticle from '@/view/searchArticle'
import notfound from '@/view/404'
import unlogin from '@/view/unlogin'
import userInformationAndArticle from '@/view/userInformationAndArticle'
Vue.use(Router)
export default new Router({
  mode:'history',
 routes : [
    {
      path: '/',
      name: 'index',
      component: index,
    },
    {
      path:'/attention',
      name:'attention',
      component:attention
    },
    {
      path:'/about',
      name:'about',
      component:about
    },
    {
      path:'/writearticle',
      name:'writeArticle',
      component:writeArticle
    },
    {
      path:'/register',
      name:'register',
      component:register
    },
    {
      path:'/login',
      name:'login',
      component:login,
    },
    {
      path:'/comment',
      name:'comment',
      component:comment
    },
    {
      path:'/search',
      name:'search',
      component:searchArticle
    },
    {
     path:'/unlogin',
     name:'unlogin',
     component:unlogin
    },
    {
      path: '/404',
      name: 'NotFound',
      component:notfound
    },
    {
      path:'/userAndArticle',
      name:'userAndArticle',
      component:userInformationAndArticle
    },
    {
      path: '*',
      redirect: '/404'
    }
  ]
})
//   const router = new Router({
//     mode: 'hash',
//     base: process.env.BASE_URL,
//     scrollBehavior: () => ({ y: 0 }),
//     routes
//   });
//   router.beforeEach((to,from,next) => {
//     var token=getToken()
//     if(token==undefined&&to.name!=='login'&&to.name!='register'){
//       alert('请先回到登陆页面')
//        router.back({
//         name:'login'
//        })
//     }else {
//       next()
//     }
// })

// router.beforeEach((to, from, next) => {

// })
//   export default router;